<?php

namespace Module\AdminLoginBackground\Core;

use Illuminate\Events\Dispatcher;
use Illuminate\Support\Facades\View;
use Illuminate\Support\ServiceProvider;
use ModStart\Admin\Config\AdminMenu;
use ModStart\Core\Hook\ModStartHook;

class ModuleServiceProvider extends ServiceProvider
{
    /**
     * Bootstrap any application services.
     *
     * @return void
     */
    public function boot(Dispatcher $events)
    {
        AdminMenu::register(function () {
            return [
                [
                    'title' => L('Admin Manage'),
                    'icon' => 'user-o',
                    'sort' => 500,
                    'children' => [
                        [
                            'title' => '管理登录背景',
                            'url' => '\Module\AdminLoginBackground\Admin\Controller\ConfigController@index',
                        ],
                    ]
                ],
            ];
        });
    }

    /**
     * Register any application services.
     *
     * @return void
     */
    public function register()
    {
        ModStartHook::subscribe('AdminLoginHeadAppend', function () {
            $type = modstart_config('AdminLoginBackground_Type', 'none');
            if ('none' == $type) {
                return null;
            }
            return View::make('module::AdminLoginBackground.View.part.css', [
                'type' => $type,
            ])->render();
        });
    }
}
